"use strict"

/**
 *  Usually we need config sms gateway via options, e.g.
        gateway: 'https://smsgateway.com'
        username: 'abc'
        password: '123'
 */
exports = module.exports = function(options){
  let webRequest  = require('request');

  let gateway   = options.gateway;
  let username  = options.username;
  let password  = options.password;

  return {
    send: function(identity, message, done){
      console.log("send message " + message + " to " + identity);

      webRequest.post(gateway
            , { form:{ account:username, password: password, mobile:identity, content: message } }
            , function(err, res){
              if(err) return done(err);

              return done(null, res);
            });
    }
  }
}
